<template>
  <div class="videos-page">
    <!-- 页面头部 -->
    <header class="page-header">
      <div class="header-background">
        <div class="header-overlay"></div>
        <video class="header-video" autoplay loop muted playsinline>
          <source src="@/assets/videos/header-bg.mp4" type="video/mp4">
        </video>
      </div>
      <div class="header-top">
        <div class="header-container">
          <div class="logo">
            <router-link to="/">
              <h1>VideoHub</h1>
            </router-link>
          </div>
          <div class="header-right">
            <div class="search-box">
              <el-input
                v-model="searchQuery"
                placeholder="搜索你感兴趣的内容"
                prefix-icon="el-icon-search"
                clearable
                @keyup.enter="handleSearch"
              >
                <template #append>
                  <el-button @click="handleSearch">搜索</el-button>
                </template>
              </el-input>
            </div>
            <div class="auth-buttons">
              <router-link to="/auth?type=login" class="auth-btn login">登录</router-link>
              <router-link to="/auth?type=register" class="auth-btn register">注册</router-link>
            </div>
          </div>
        </div>
      </div>
      <div class="header-content">
        <div class="header-main">
          <h2>发现精彩视界</h2>
          <p class="header-subtitle">海量视频内容，总有你想看的</p>
        </div>
        <div class="quick-stats">
          <div class="stat-item">
            <span class="stat-number">10,000+</span>
            <span class="stat-label">视频总数</span>
          </div>
          <div class="stat-item">
            <span class="stat-number">50+</span>
            <span class="stat-label">每日更新</span>
          </div>
          <div class="stat-item">
            <span class="stat-number">100万+</span>
            <span class="stat-label">用户观看</span>
          </div>
        </div>
      </div>
    </header>

    <!-- 导航标签栏 -->
    <nav class="nav-tabs">
      <div class="tabs-container">
        <router-link 
          v-for="tab in navigationTabs" 
          :key="tab.path"
          :to="tab.path"
          class="nav-tab"
          :class="{ active: currentTab === tab.path }"
        >
          <i :class="tab.icon"></i>
          {{ tab.name }}
        </router-link>
      </div>
    </nav>

    <!-- 高级筛选按钮 -->
    <div class="advanced-filter-toggle">
      <el-button 
        type="text" 
        @click="toggleFilter"
        :icon="isFilterExpanded ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
      >
        高级筛选
      </el-button>
    </div>

    <!-- 筛选区域 -->
    <section class="filter-section" v-show="isFilterExpanded">
      <div class="filter-container">
        <!-- 分类筛选 -->
        <div class="filter-group">
          <h3>分类</h3>
          <div class="filter-tags">
            <button 
              v-for="category in categories" 
              :key="category.id"
              :class="['filter-tag', { active: selectedCategory === category.id }]"
              @click="selectCategory(category.id)"
            >
              {{ category.name }}
            </button>
          </div>
        </div>

        <!-- 类型筛选 -->
        <div class="filter-group">
          <h3>类型</h3>
          <div class="filter-tags">
            <button 
              v-for="type in types" 
              :key="type.id"
              :class="['filter-tag', { active: selectedType === type.id }]"
              @click="selectType(type.id)"
            >
              {{ type.name }}
            </button>
          </div>
        </div>

        <!-- 年份筛选 -->
        <div class="filter-group">
          <h3>年份</h3>
          <div class="filter-tags">
            <button 
              v-for="year in years" 
              :key="year"
              :class="['filter-tag', { active: selectedYear === year }]"
              @click="selectYear(year)"
            >
              {{ year }}
            </button>
          </div>
        </div>

        <!-- 排序方式 -->
        <div class="filter-group sort-group">
          <h3>排序</h3>
          <el-select v-model="sortBy" placeholder="请选择排序方式" class="sort-select">
            <el-option
              v-for="item in sortOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
      </div>
    </section>

    <!-- 视频列表 -->
    <section class="videos-section">
      <div class="videos-grid">
        <div v-for="video in displayedVideos" 
             :key="video.id" 
             class="video-card"
             @click="navigateToVideo(video.id)">
          <div class="video-thumbnail">
            <img :src="video.thumbnail" :alt="video.title">
            <span class="video-duration">{{ video.duration }}</span>
            <div class="video-overlay">
              <i class="play-icon"></i>
            </div>
          </div>
          <div class="video-info">
            <h3>{{ video.title }}</h3>
            <div class="video-meta">
              <span class="video-category">{{ video.category }}</span>
              <span class="video-views">{{ video.views }}次观看</span>
            </div>
            <p class="video-desc">{{ video.description }}</p>
          </div>
        </div>
      </div>

      <!-- 高级分页 -->
      <div class="pagination-container" v-if="totalPages > 1">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[12, 24, 36, 48]"
          :total="totalVideos"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
        />
      </div>
    </section>

    <!-- 无结果提示 -->
    <div class="no-results" v-if="displayedVideos.length === 0">
      <el-empty description="暂无符合条件的视频" />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'Videos',
  data() {
    return {
      isFilterExpanded: false,
      searchQuery: '',
      currentTab: '/videos',
      navigationTabs: [
        { name: '全部', path: '/videos', icon: 'el-icon-video-camera' },
        { name: '电影', path: '/videos/movies', icon: 'el-icon-film' },
        { name: '电视剧', path: '/videos/tv', icon: 'el-icon-monitor' },
        { name: '动漫', path: '/videos/anime', icon: 'el-icon-picture' }
      ],
      // 筛选选项
      selectedCategory: null,
      selectedType: null,
      selectedYear: null,
      sortBy: 'newest',

      // 分页
      currentPage: 1,
      pageSize: 12,
      totalVideos: 156,

      // 筛选选项数据
      categories: [
        { id: 1, name: '电影' },
        { id: 2, name: '电视剧' },
        { id: 3, name: '动漫' },
        { id: 4, name: '综艺' },
        { id: 5, name: '纪录片' },
        { id: 6, name: '体育' }
      ],
      types: [
        { id: 1, name: '动作' },
        { id: 2, name: '喜剧' },
        { id: 3, name: '爱情' },
        { id: 4, name: '科幻' },
        { id: 5, name: '恐怖' },
        { id: 6, name: '剧情' }
      ],
      years: [2024, 2023, 2022, 2021, 2020],
      sortOptions: [
        { value: 'newest', label: '最新上传' },
        { value: 'hottest', label: '最多播放' },
        { value: 'rating', label: '最高评分' }
      ],

      // 视频数据
      videos: [
        {
          id: 1,
          title: '奥本海默',
          description: '诺兰导演力作，奥斯卡获奖电影',
          thumbnail: '/images/featured/oppenheimer.jpg',
          duration: '180:00',
          category: '电影',
          views: '156万',
          rating: 9.2
        },
        // ... 更多视频数据
      ]
    }
  },
  computed: {
    displayedVideos() {
      // 首先根据当前路由筛选视频类型
      let filtered = this.videos.filter(video => {
        switch (this.$route.path) {
          case '/videos/movies':
            return video.category === '电影'
          case '/videos/tv':
            return video.category === '电视剧'
          case '/videos/anime':
            return video.category === '动漫'
          default:
            return true // 在 /videos 路径下显示所有视频
        }
      })

      // 然后应用高级筛选条件
      if (this.selectedCategory) {
        filtered = filtered.filter(v => v.categoryId === this.selectedCategory)
      }
      if (this.selectedType) {
        filtered = filtered.filter(v => v.typeId === this.selectedType)
      }
      if (this.selectedYear) {
        filtered = filtered.filter(v => v.year === this.selectedYear)
      }

      // 排序
      filtered = filtered.sort((a, b) => {
        switch (this.sortBy) {
          case 'hottest':
            return b.views - a.views
          case 'rating':
            return b.rating - a.rating
          default:
            return b.uploadTime - a.uploadTime
        }
      })

      return filtered
    },
    totalPages() {
      return Math.ceil(this.totalVideos / this.pageSize)
    }
  },
  methods: {
    toggleFilter() {
      this.isFilterExpanded = !this.isFilterExpanded
    },
    handleSearch() {
      // 实现搜索逻辑
      console.log('Searching for:', this.searchQuery)
    },
    selectCategory(categoryId) {
      this.selectedCategory = this.selectedCategory === categoryId ? null : categoryId
      this.currentPage = 1
    },
    selectType(typeId) {
      this.selectedType = this.selectedType === typeId ? null : typeId
      this.currentPage = 1
    },
    selectYear(year) {
      this.selectedYear = this.selectedYear === year ? null : year
      this.currentPage = 1
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
    },
    handleCurrentChange(val) {
      this.currentPage = val
    },
    navigateToVideo(id) {
      this.$router.push(`/video/${id}`)
    }
  },
  watch: {
    '$route'(to) {
      this.currentTab = to.path
    }
  }
})
</script>

<style scoped>
.videos-page {
  min-height: 100vh;
  background-color: #f5f5f7;
}

/* 页面头部样式 */
.page-header {
  position: relative;
  height: 480px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
}

.header-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.header-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0.5) 100%
  );
  z-index: 2;
}

.header-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  padding: 1rem 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
}

.logo a {
  text-decoration: none;
  color: white;
}

.logo h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(45deg, #fff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.search-box {
  width: 400px;
}

.auth-buttons {
  display: flex;
  gap: 1rem;
}

.auth-btn {
  padding: 0.6rem 1.5rem;
  border-radius: 20px;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.auth-btn.login {
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.auth-btn.login:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: white;
}

.auth-btn.register {
  background: white;
  color: #1a1a1a;
}

.auth-btn.register:hover {
  background: #f0f0f0;
  transform: translateY(-2px);
}

.header-content {
  position: relative;
  z-index: 3;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  padding-top: 6rem;
  color: white;
  text-align: center;
}

.header-main {
  margin-bottom: 3rem;
}

.header-main h2 {
  font-size: 3.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  background: linear-gradient(45deg, #fff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-subtitle {
  font-size: 1.5rem;
  margin-bottom: 2rem;
  opacity: 0.9;
}

.quick-stats {
  display: flex;
  justify-content: center;
  gap: 4rem;
  margin-top: 3rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(45deg, #fff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: 1rem;
  opacity: 0.8;
}

/* 导航标签栏样式 */
.nav-tabs {
  background: white;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tabs-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  gap: 2rem;
}

.nav-tab {
  padding: 1.2rem 2rem;
  color: #666;
  text-decoration: none;
  font-size: 1.1rem;
  position: relative;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-tab i {
  font-size: 1.2rem;
}

.nav-tab:hover {
  color: #007bff;
}

.nav-tab.active {
  color: #007bff;
}

.nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: #007bff;
  border-radius: 3px 3px 0 0;
}

/* 高级筛选按钮样式 */
.advanced-filter-toggle {
  max-width: 1400px;
  margin: 1rem auto;
  padding: 0 2rem;
  text-align: right;
}

.advanced-filter-toggle .el-button {
  font-size: 1rem;
  color: #666;
}

.advanced-filter-toggle .el-button:hover {
  color: #007bff;
}

/* 修改筛选区域样式 */
.filter-section {
  background: white;
  padding: 2rem 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 2rem;
  transition: all 0.3s ease;
}

.filter-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
}

.filter-group {
  margin-bottom: 1.5rem;
}

.filter-group:last-child {
  margin-bottom: 0;
}

.filter-group h3 {
  font-size: 1rem;
  color: #666;
  margin-bottom: 1rem;
}

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.filter-tag {
  padding: 0.5rem 1.2rem;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
}

.filter-tag:hover {
  border-color: #007bff;
  color: #007bff;
}

.filter-tag.active {
  background: #007bff;
  color: white;
  border-color: #007bff;
}

.sort-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.sort-select {
  width: 200px;
}

/* 视频列表样式 */
.videos-section {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 2rem;
}

.videos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 2rem;
  margin-bottom: 3rem;
}

.video-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.video-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.video-thumbnail {
  position: relative;
  padding-top: 56.25%; /* 16:9 比例 */
}

.video-thumbnail img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.video-card:hover .video-overlay {
  opacity: 1;
}

.video-duration {
  position: absolute;
  bottom: 0.8rem;
  right: 0.8rem;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.video-info {
  padding: 1.2rem;
}

.video-info h3 {
  font-size: 1.1rem;
  margin: 0 0 0.8rem;
  color: #1a1a1a;
}

.video-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  color: #666;
}

.video-desc {
  font-size: 0.9rem;
  color: #666;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 分页样式 */
.pagination-container {
  display: flex;
  justify-content: center;
  margin-top: 3rem;
  padding-bottom: 3rem;
}

/* 无结果提示样式 */
.no-results {
  text-align: center;
  padding: 4rem 0;
}

@media (max-width: 1024px) {
  .header-container {
    padding: 0 1rem;
  }

  .search-box {
    width: 300px;
  }

  .auth-btn {
    padding: 0.5rem 1rem;
  }
}

@media (max-width: 768px) {
  .header-top {
    padding: 0.5rem 0;
  }

  .logo h1 {
    font-size: 1.5rem;
  }

  .header-right {
    gap: 1rem;
  }

  .search-box {
    width: 200px;
  }

  .auth-buttons {
    gap: 0.5rem;
  }

  .auth-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  .header-main h2 {
    font-size: 2.5rem;
  }

  .nav-tabs {
    overflow-x: auto;
  }

  .tabs-container {
    justify-content: flex-start;
    padding: 0 1rem;
  }

  .nav-tab {
    padding: 1rem 1.5rem;
    font-size: 1rem;
    white-space: nowrap;
  }

  .filter-container {
    padding: 0 1rem;
  }

  .videos-section {
    padding: 0 1rem;
  }

  .videos-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }
}
</style> 